package com.example.mynote.activity;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import com.bumptech.glide.Glide;
import com.example.mynote.R;
import com.example.mynote.base.BaseActivity;
import com.example.mynote.fragment.NoteFragment;
import com.example.mynote.fragment.StickFragment;
import com.example.mynote.fragment.PersonFragment;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {

    private androidx.viewpager2.widget.ViewPager2 mainPage;
    private com.google.android.material.tabs.TabLayout mainTab;
    Integer[] icon = {R.mipmap.main_3, R.mipmap.main_icon1, R.mipmap.main_icon2};
    private List<Fragment> fragments = new ArrayList<>();
    private String[] text = {"便签", "日记", "我的"};
    private android.widget.TextView title;

    @Override
    protected int initLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        mainPage = (ViewPager2) findViewById(R.id.main_page);
        mainTab = (TabLayout) findViewById(R.id.main_tab);
        title = (TextView) findViewById(R.id.title);
    }

    @Override
    protected void initData() {

        fragments.add(new StickFragment());
        fragments.add(new NoteFragment());
        fragments.add(new PersonFragment());

        mainPage.setAdapter(new FragmentStateAdapter(getSupportFragmentManager(), getLifecycle()) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                return fragments.get(position);
            }

            @Override
            public int getItemCount() {
                return fragments.size();
            }
        });

        mainPage.getChildAt(0).setOverScrollMode(View.OVER_SCROLL_NEVER);

        new TabLayoutMediator(mainTab, mainPage, false, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(text[position]);
                tab.setIcon(icon[position]);
            }
        }).attach();
    }
}